#include "../VoicePlayer_h/VoiceFileConfig.h"
#include "../Error_h/error.h"
#include <QFile>
#include <QTextStream>
#include <QVector>

VoiceFileConfig* VoiceFileConfig::_instance = NULL;

VoiceFileConfig::VoiceFileConfig(){

}

VoiceFileConfig* VoiceFileConfig::GetInstance(){
    if(!_instance) _instance = new VoiceFileConfig();

    return _instance;
}

int VoiceFileConfig::ReadFile(QString configFilePath){
    QFile configFile(configFilePath);
    //打开失败
    if(!configFile.open(QIODevice::ReadOnly|QIODevice::Text)){
        return OPEN_CONFIG_FILE_ERROR;
    }

    QTextStream stream(&configFilePath);
    QVector<QString> lineStr;
    while(!stream.atEnd()){
        lineStr.append(stream.readLine());
    }

    int configNum = lineStr[0].toInt();

    //配置文件所写的值不足指定的数量时
    if(lineStr.size()<configNum){
        return CONFIG_NUM_NOT_ENOUGH_ERROR;
    }

    //逐一赋值
    for(int i = 0;i<configNum;++i){
        switch (i) {
        case 0:
            _voiceFilePath = lineStr[i];
            break;
        default:
            break;
        }
    }

    return NONE;
}
